<template>
  <div class="page-hero">
    <div class="topbar py-2 px-3 d-flex ai-center text-white" style="background: rgb(23, 24, 35)">
      <img src="../assets/logo.png" height="30">
      <div class="px-3 flex-1">
        <span>王者荣耀</span>
        <span class="ml-3">攻略战</span>
      </div>
      <router-link to="/" tag="div" class="fs-sm">
        更多英雄
        <i class="iconfont icon-qianji fs-sm"></i>
      </router-link>
    </div>
    <div class="top" :style="{'background-image':`url(${model.banner})`}">
      <div class="info text-white p-3 h-100 d-flex flex-column jc-end">
        <div class="fs-sm">{{model.title}}</div>
        <h2 class="my-2 fs-xl">{{model.name}}</h2>
        <div class="fs-sm">{{model.categories.map(v => v.name).join('/')}}</div>
        <div class="d-flex jc-between pt-1">
          <div class="scores d-flex ai-center fs-sm">
            <span>难度</span>
            <span class="badge bg-primary">{{model.scores.difficult}}</span>
            <span>技能</span>
            <span class="badge bg-blue-1">{{model.scores.skills}}</span>
            <span>攻击</span>
            <span class="badge bg-danger">{{model.scores.attack}}</span>
            <span>生存</span>
            <span class="badge bg-dark">{{model.scores.survive}}</span>
          </div>
          <router-link tag="span" to="/" class="text-grey fs-xs">
            皮肤：2
            <i class="iconfont icon-qianji fs-sm"></i>
          </router-link>
        </div>
      </div>
    </div>
    <!-- end of top -->
    <div>
      <div class="bg-white px-3">
        <div class="nav d-flex jc-around pt-3 pb-2 border-bottom">
          <div class="nav-item active">
            <div class="nav-link">英雄初始</div>
          </div>
          <div class="nav-item">
            <div class="nav-link">进阶攻略</div>
          </div>
        </div>
      </div>
      <swiper>
        <swiper-slide>
          <div>
            <div class="p-3 bg-white border-bottom">
              <div class="d-flex">
                <router-link tag="button" to="/" class="btn btn-lg flex-1">
                  <i class="iconfont icon-video"></i>
                  英雄介绍
                </router-link>
                <router-link tag="button" to="/" class="btn btn-lg flex-1 ml-2">
                  <i class="iconfont icon-video"></i>
                  一图识英雄
                </router-link>
              </div>
                <!-- skills -->
              <div class="skills mt-4"  v-if="model.skills">
                <div class="d-flex jc-around">
                  <img :src="item.icon"
                  class="icon"
                  :class="{active: currentSkillIndex === i}"
                  @click="currentSkillIndex=i"
                  v-for="(item,i) in model.skills"
                  :key="item.name">
                </div>
                <div v-if="currentSkill">
                  <div class="d-flex pt-4 pb-3">
                    <h3 class="m-0">{{currentSkill.name}}</h3>
                    <span class="text-grey-1 ml-4">
                      (冷却值：{{currentSkill.delay}}
                      消耗：{{currentSkill.cost}})
                    </span>
                  </div>
                  <p class="m-0">{{currentSkill.description}}</p>
                </div>
              </div>
            </div>
            <m-card plain icon="menu" title="出装推荐" class="hero-items">
              <div class="fs-xl">顺风出装</div>
              <div class="d-flex jc-around text-center mt-3">
                <div v-for="item in model.items1" :key="item.name">
                  <img :src="item.icon" class="icon">
                  <div class="fs-xs">{{item.name}}</div>
                </div>
              </div>
              <div class="border-bottom mt-3"></div>
              <div class="fs-xl mt-3">逆风出装</div>
              <div class="d-flex jc-around text-center mt-3">
                <div v-for="item in model.items2" :key="item.name">
                  <img :src="item.icon" class="icon">
                  <div class="fs-xs">{{item.name}}</div>
                </div>
              </div>
            </m-card>
            <m-card plain icon="menu" title="使用技巧">
              <p class="m-0">{{model.usageTips}}</p>
            </m-card>
            <m-card plain icon="menu" title="对抗技巧">
              <p class="m-0">{{model.battleTips}}</p>
            </m-card>
            <m-card plain icon="menu" title="团战思路">
              <p class="m-0">{{model.teamTips}}</p>
            </m-card>
            <m-card plain icon="menu" title="英雄关系">
              <div class="fs-xl">最佳搭档</div>
              <div v-for="item in model.partners" :key="item.name" class="d-flex pt-4">
                <img :src="item.hero.avatar" height="50">
                <p class="flex-1 m-0 ml-3">
                  {{item.description}}
                </p>
              </div>
              <!-- <div class="border-bottom mt-3"></div> -->
            </m-card>
          </div>
        </swiper-slide>
        <swiper-slide></swiper-slide>
      </swiper>
    </div>
    <div class="mt-4"></div>
  </div>
</template>

<script>
export default {
  props: {
    id: { type: String, required: true }
  },
  data () {
    return {
      model: {
        avatar: '',
        banner: '',
        battleTips: '',
        usageTips: '',
        name: '',
        partners: '',
        titles: '',
        items1: '',
        items2: '',
        scores: [],
        skills: [],
        categories: []
      },
      currentSkillIndex: 0
    }
  },
  computed: {
    currentSkill () {
      return this.model.skills[this.currentSkillIndex]
    }
  },
  methods: {
    async fetch () {
      const res = await this.$http.get(`/heroes/${this.id}`)
      // console.log(res.data)
      this.model = res.data
    }
  },
  created () {
    this.fetch()
  }
}
</script>

<style lang="scss">
@import '../assets/scss/_variables.scss';
.page-hero {
  .top {
    height: 50vw;
    background: #fff no-repeat top center;
    background-size: auto 100%;
  }
  .info {
    background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));
    .scores {
      .badge {
        margin: 0 0.6rem;
        display: inline-block;
        width: 1rem;
        height: 1rem;
        line-height: 0.9rem;
        text-align: center;
        border-radius: 50%;
        font-size: 0.6rem;
        border: 1px solid rgba(255,255,255,0.3);
      }
    }
  }
  .skills {
    img {
      width: 65px;
      height: 65px;
      border: 3px solid map-get($map: $colors, $key: 'white');
      border-radius: 40%;
      &.active {
        border: 3px solid map-get($map: $colors, $key: 'primary');
      }
    }
  }
  .hero-items {
    img.icon {
      width: 3.4615rem;
      height: 3.4615rem;
      border-radius: 50%;
    }
  }
}
</style>
